package name.huzhenbo.java.patterns.command;

import java.util.ArrayList;
import java.util.List;

class MarsEngine {
    private Platform platform;
    private Rover rover;

    MarsEngine(Platform platform, Rover rover) {
        this.platform = platform;
        this.rover = rover;
    }

    Rover executeCmd(String cmd) {
        List<RoverCommand> roverCommands = parseCommand(cmd);
        for (RoverCommand roverCommand : roverCommands) {
            roverCommand.execute(rover);
        }
        return rover;
    }

    private List<RoverCommand> parseCommand(String cmd) {
        List<RoverCommand> roverCommands = new ArrayList<RoverCommand>();
        if (cmd == null) {
            return roverCommands;
        }
        for (char c : cmd.toCharArray()) {
            roverCommands.add(RoverCommand.valueof(c));
        }
        return roverCommands;
    }
}
